<?php
class UI {
	// define("POS_HEAD", CClientScript::POS_HEAD);
	// define("POS_BEGIN", CClientScript::POS_BEGIN);
	// define("POS_END", CClientScript::POS_END);
	// define("POS_READY", CClientScript::POS_READY);
	// define("POS_LOAD", CClientScript::POS_LOAD);
	public $pos = array(
		'begin' => CClientScript::POS_BEGIN,
		'head' => CClientScript::POS_HEAD,
		'end' => CClientScript::POS_END,
		'ready' => CClientScript::POS_READY,
		'load' => CClientScript::POS_LOAD,
	);
	public $cssUrl;
	public $jsUrl;

	function __construct(){
		$this->jsUrl = Yii::app()->baseUrl.'/js/';
		$this->cssUrl = Yii::app()->baseUrl.'/css/';
	}

	public function loadUI($listUI){
		foreach($listUI as $ui){
			if(!method_exists($this, $ui)) continue;
			$assets = $this->$ui();
			foreach($assets['css'] as $css){
				$this->loadCssFile($css);
			}
			foreach($assets['js'] as $js){
				$this->loadJsFile($js, $this->pos['end']);
			}
		}
	}

	public function initUI(){
		$this->loadUI(array(
			'UICore', 
			// 'uniform',
			'placeholder', 
			'datatable',
			'excanvas',
			'choosen',
			'noty', 
			'imagesloaded',
			'iostoggle',
			'autosize',
			'retina'
			));
	}

	public function loadJsFile($file, $pos = NULL){
		Yii::app()->clientScript->registerScriptFile($this->jsUrl.$file, $pos);
	} 

	public function loadCssFile($file, $media = ''){
		Yii::app()->clientScript->registerCssFile($this->cssUrl.$file, $media);
	}

	public function addCss($id, $css, $media){
		Yii::app()->clientScript->registerCss($id, $css, $media);
	}

	public function addScript($id, $script, $position=NULL){
		Yii::app()->clientScript->registerScript($id, $script, $position);
	}

	// UI CORE
	private function UICore(){
		return array(
			'css' => array(
			),
			'js' => array(
		        // "jquery-1.10.2.min.js",
		        "jquery-migrate-1.2.1.min.js",
		        "jquery-ui-1.10.3.custom.min.js",
		        "jquery.ui.touch-punch.js",
		        "modernizr.js",
		        "bootstrap.min.js",
		        "jquery.cookie.js",
		        "core.min.js",
		        'custom/common.js',
		        // "charts.min.js",
			)
		);
	}	

	private function placeholder(){
		return array(
			'css' => array(

			),
			'js' => array(
				'jquery.placeholder.min.js'
			)
		);
	}

	private function calendar(){
		return array(
			'css' => array(
				'fullcalendar.css'
			),
			'js' => array(
				'fullcalendar.min.js'
			)
		);
	}

	private function datatable(){
		return array(
			'css' => array(
			),
			'js' => array(
				'jquery.dataTables.min.js'
			)
		);
	}	

	private function excanvas(){
		return array(
			'css' => array(
			),
			'js' => array(
				'excanvas.js'
			)
		);
	}	

	private function choosen(){
		return array(
			'css' => array(
				'chosen.css'
			),
			'js' => array(
				'jquery.chosen.min.js'
			)
		);
	}

	// flotcharts là vẽ biểu đồ demo http://www.flotcharts.org/
	private function chart(){
		return array(
			'css' => array(
			),
			'js' => array(
				'jquery.flot.js',
				'jquery.flot.pie.js',
				'jquery.flot.stack.js',
				'jquery.flot.resize.min.js',
				'jquery.flot.time.js',
			)
		);
	}

	// Biểu đồ dạng tròn demo http://anthonyterrien.com/knob/
	private function knob(){
		return array(
			'css' => array(
			),
			'js' => array(
				'jquery.knob.modified.js'
			)
		);
	}
	
	// Biểu đồ dạng tròn nữa demo http://justgage.com/
	private function justgage(){
		return array(
			'css' => array(
			),
			'js' => array(
				'justgage.1.0.1.min.js'
			)
		);
	}

	// Form style
	private function uniform(){
		return array(
			'css' => array(
				"uniform.default.css"
			),
			'js' => array(
				'jquery.uniform.min.js'
			)
		);
	}

	// Hiện thông báo
	private function noty(){
		return array(
			'css' => array(
				"jquery.noty.css",
				"noty_theme_default.css"
			),
			'js' => array(
				'jquery.noty.js'
			)
		);
	}

	// UI đánh giá - rating demo http://wbotelhos.com/raty/
	private function raty(){
		return array(
			'css' => array(
			),
			'js' => array(
				'jquery.raty.min.js'
			)
		);
	}

	// UI uploader demo http://www.uploadify.com/
	private function uploadify(){
		return array(
			'css' => array(
				"uploadify.css"
			),
			'js' => array(
				'jquery.uploadify-3.1.min.js'
			)
		);
	}	

	// UI file manager demo http://elfinder.org/
	private function elfinder(){
		return array(
			'css' => array(
				"elfinder.min.css",
				"elfinder.theme.css"
			),
			'js' => array(
				'jquery.elfinder.min.js'
			)
		);
	}

	// UI trình soạn thảo
	private function editor(){
		return array(
			'css' => array(
				"jquery.cleditor.css"
			),
			'js' => array(
				'jquery.cleditor.min.js'
			)
		);
	}

	// UI tự động resize textarea Demo http://www.jacklmoore.com/autosize/
	private function autosize(){
		return array(
			'css' => array(
			),
			'js' => array(
				'jquery.autosize.min.js'
			)
		);
	}

	// UI preloaded image 
	private function imagesloaded(){
		return array(
			'css' => array(
			),
			'js' => array(
				'jquery.imagesloaded.js'
			)
		);
	}

	// UI IOS toggle on/off
	private function iostoggle(){
		return array(
			'css' => array(
				'jquery.iphone.toggle.css'
			),
			'js' => array(
				'jquery.iphone.toggle.js'
			)
		);
	}

	private function sparkline(){
		return array(
			'css' => array(
			),
			'js' => array(
				'jquery.sparkline.min.js'
			)
		);
	}

	private function wizard(){
		return array(
			'css' => array(
			),
			'js' => array(
				"wizard.min.js"
			)
		);
	}
	private function masonry(){
		return array(
			'css' => array(
			),
			'js' => array(
				"jquery.masonry.min.js"
			)
		);
	}

	private function autosuggest(){
		return array(
			'css' => array(
				'jquery.autoSuggest.css'
			),
			'js' => array(
				"jquery.autoSuggest.js"
			)
		);		
	}

}
?>